/*
 *  Copyright 2014-2023 The GmSSL Project. All Rights Reserved.
 *
 *  Licensed under the Apache License, Version 2.0 (the License); you may
 *  not use this file except in compliance with the License.
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gmssl/sm2.h>
#include <gmssl/rand.h>
#include <gmssl/error.h>


int main(void)
{
	SM2_POINT P;
	uint8_t uncompressed[65] = {
		0x04,
		0x0e,0x90,0x75,0x97,0x92,0x4f,0x48,0x6d,
		0x9f,0xa9,0x58,0x63,0xeb,0xb2,0x7b,0xa5,
		0xd2,0xc7,0x77,0x64,0x2c,0x94,0x8f,0x32,
		0xda,0x3a,0xd6,0xef,0xef,0xe4,0xda,0xaf,
		0x41,0x70,0x92,0x65,0x4f,0xf8,0x81,0x57,
		0x70,0x83,0x00,0xab,0x71,0xae,0xb0,0xaf,
		0x7b,0x55,0xe1,0x45,0xc7,0x9d,0xfb,0xcc,
		0xf4,0x10,0xff,0xe3,0x32,0xc4,0xcb,0x07,
	};

	if (sm2_point_from_octets(&P, uncompressed, 65) != 1) {
		fprintf(stderr, "sm2_point_from_octets() error\n");
		goto err;
	}
	printf("sm2_point_from_octets() success\n");

	rand_bytes(uncompressed + 1, 64);
	if (sm2_point_from_octets(&P, uncompressed, 65) != 1) {
		fprintf(stderr, "sm2_point_from_octets() error\n");
		goto err;
	}

err:
	return 0;
}
